TreeNode* PrePost(vector<int>& pre,vector<int>& post,int l1,int l2,int r1,int r2)
{
	if (l1 > l2)
	{
		return nullptr;
	}
	
	//先放根节点
	TreeNode* root = new TreeNode(pre[l1]);
	if (l1 == l2)
	{
		return root;
	}

	//左子树
	int index;
	for (index = 0; post[index] != pre[l1+1]; index++)
	{
	}

	int left_len = index - r1 + 1;
	int r_len = r2 - index - 1;

	root->left = PrePost(pre, post, l1 + 1, l1 + left_len, r1, index);

	root->right = PrePost(pre, post, l2 - r_len+1, l2, index+1, index + r_len);

	return root;


};
class Solution {
public:
	TreeNode* constructFromPrePost(vector<int>& preorder, vector<int>& postorder) 
	{
		
		//解法和前两种一致。
		return PrePost(preorder, postorder, 0, preorder.size() - 1, 0, postorder.size() - 1);
	}
};